/**
 * @Title: UserController.java
 * @Description:
 * @author zsw
 * <p>
 * Copyright(C) 2018-2019    NPlus
 * Company:   无锡核心信息科技有限公司
 * @version V2.0.0
 * @Date: 13:30 2019/10/17
 * <p>
 * 修改历史:
 * Date                 Author        Version        Description
 * -----------------------------------------------------------------------------------
 * 13:30 2019/10/17       zsw        2.0.0           初始化版本
 */
package com.example.springjpa.controller;

import com.example.springjpa.common.CommonResult;
import com.example.springjpa.model.User;
import com.example.springjpa.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
//@EnableScheduling //启用定时器
public class UserController {

    @Autowired
    private UserService userService;
    CommonResult commonResult = new CommonResult();

  //  @Scheduled(cron = "0/5 * * * * ?")
    public void test(){
        log.info("当前时间："+System.currentTimeMillis());
    }
    @GetMapping("/user/test/{id}")
    public CommonResult getUser(@PathVariable Long id) {
        User user = userService.getUser(id);
        commonResult.setData(user);
        return commonResult;
    }

    @PostMapping("/user/test/")
    public CommonResult postUser(User user) {
        userService.add(user);
        commonResult.setData(user);
        return commonResult;
    }
}
